package com.veo.confilg;

import com.veo.component.LoginInterceptorHandler;
import com.veo.component.MyLocaleResolver;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.LocaleResolver;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebMvcConfig implements WebMvcConfigurer {

//    /*方法1*/
//    @Override
//    public void addViewControllers(ViewControllerRegistry registry) {
//        registry.addViewController("/").setViewName("login");
//    }


    /*方法2*/
    @Bean//注入ioc容器
    public WebMvcConfigurer webMvcConfigurer(){
        WebMvcConfigurer webMvcConfigurer = new WebMvcConfigurer(){
            @Override
            public void addViewControllers(ViewControllerRegistry registry) {
                registry.addViewController("/").setViewName("login");
                registry.addViewController("/hello").setViewName("success");
                registry.addViewController("/toLogin").setViewName("login");
                registry.addViewController("/toMain").setViewName("dashboard");


            }

            //配置登录拦截器
            @Override
            public void addInterceptors(InterceptorRegistry registry) {
//                registry.addInterceptor(new LoginInterceptorHandler()).addPathPatterns("/**")
//                        //路径排除要注意**********************************
//                        .excludePathPatterns("/static/**","/webjars/**","/asserts/**","/","/toLogin","/hello","/user","/user/login");
            }
        };
        return webMvcConfigurer;
    }


    /*配置区域解析信息*/
    @Bean
    public LocaleResolver localeResolver(){
        return new MyLocaleResolver();
    }


}
